// const http = require("http");
const express = require("express");
const url = require("url");
const path = require("path");
const fs = require("fs");
const bodyParser = require("body-Parser");
// const server = http.createServer();
const server = express();
const cors = require("cors");
server.use(cors);

server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());
server.post("/login", (req, res, next) => {
  res.render(path.join(__dirname, "add.html"));
  console.log(req.url);
  let { query } = url.parse(req.url, true);
  console.log(query);

  var list = [];
  list.push(query);

  fs.writeFile(
    path.join(__dirname, "data", "data.json"),
    JSON.stringify(list),
    function (err) {
      if (err) {
        throw err;
      }
      console.log("ok");
    }
  );
});

server.listen(5500);
